﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BDCS.BLL;
using BDCS.Model;

namespace BDCS.UI
{
    public partial class AddDefineAttributes : Form
    {
        #region 成员字段
        private BDCS.BLL.T_SubBuildAttributes bllSubBuildAttribute;
        private BDCS.BLL.T_SubAttributes bllSubAttribute;
        private BDCS.BLL.T_BuildDesignDcriterionSubTypes bllBuildDesignDcriterionSubType;
        private BDCS.BLL.T_BuildDesignDcriterionContents bllBuildDesignDcriterionContent;
        private BDCS.BLL.T_SubBuildDcriterionContents bllSubBuildDcriterionContent;
        private BDCS.BLL.T_SubBuildDcriterionConditions bllSubBuildDcriterionCondition;
        private BDCS.BLL.T_SubBuildDcriterionDesignAttributes bllSubBuildDcriterionDesignAttribute;
        private BDCS.BLL.T_SubBuildDcriterionList bllSubBuildDcriterionList;
        private Model.T_SubBuildDcriterionContents modelSubBuildDcriterionContent;
        private List<Model.T_SubBuildDcriterionConditions> listSubBuildDcriterionCondition;
        private Model.T_SubBuildDcriterionConditions modelSubBuildDcriterionCondition;
        private Model.T_SubBuildDcriterionDesignAttributes modelSubBuildDcriterionDesignAttribute;
        private List<Model.T_SubBuildDcriterionDesignAttributes> listSubBuildDcriterionDesignAttribute;
        private Model.T_SubBuildDcriterionList modelSubBuildDcriterionList;
        private List<Model.T_SubBuildDcriterionContents> listResult;
        private List<Model.AddConterns> listAddContent;
        private List<string> listSbdcidAttribute;
        private List<string> listSbdcidCondition;
        private List<string> listSbdcidContent;
        private List<Model.T_SubBuildAttributes> listSubBuildAttribute;
        //   private List<Model.T_SubAttributes> listSubAttribute;
        private List<Model.AddSelectAttributes> listAddSelectAttribute;
        private List<Model.AddDcriterions> listAddDcriterion;
        private DataSet dataSet;
        private int sbaid;
        private int sbtid;
        private int dtid;
        private int dstid;
        private int parentDstid;
        private int dstidTwo;
        //  private int dcidTwo;
        private bool isAdd;
        private string sbdcid;
        private string s1;
        private string s2;
        private string s3;
        private bool isSame;
        #endregion
        #region 构造函数
        public AddDefineAttributes()
        {
            InitializeComponent();
        }
        public AddDefineAttributes(int sbtid, int dtid, int dstid)
        {
            this.sbtid = sbtid;
            this.dtid = dtid;
            this.parentDstid = dstid;
            InitializeComponent();
        }
        #endregion
        private void AddDefineAttributes_Load(object sender, EventArgs e)
        {
            SubBuildAttributeDataBinding(sbtid);
            SubAttributeDataBinding(sbaid);
            CmbBuildDcriterionNameDataBinding(dtid);
            CmbBuildDcriterionContentDataBinding(dstid);
            cmbResultDcriterionDataBinding(dtid);
            cmbResulitContentDataBinding(dstidTwo);
            listSubBuildDcriterionCondition = new List<Model.T_SubBuildDcriterionConditions>();
            listSubBuildDcriterionDesignAttribute = new List<Model.T_SubBuildDcriterionDesignAttributes>();
            modelSubBuildDcriterionList = new Model.T_SubBuildDcriterionList();
            listResult = new List<Model.T_SubBuildDcriterionContents>();
            listSbdcidAttribute = new List<string>();
            listSbdcidContent = new List<string>();
            listSbdcidCondition = new List<string>();
            listSubBuildAttribute = new List<Model.T_SubBuildAttributes>();
            listResult = new List<Model.T_SubBuildDcriterionContents>();
            listAddSelectAttribute = new List<AddSelectAttributes>();
            listAddDcriterion = new List<AddDcriterions>();
            listAddContent = new List<AddConterns>();
            modelSubBuildDcriterionList.SBTID = this.sbtid;
            modelSubBuildDcriterionList.DSTID = this.parentDstid;
        }
        private void SubBuildAttributeDataBinding(int sbtid)
        {
            dataSet = new DataSet();
            bllSubBuildAttribute = new BLL.T_SubBuildAttributes();
            dataSet = bllSubBuildAttribute.GetList("SBTID=" + "'" + sbtid + "'");
            cmbSubBuildAttribute.DataSource = dataSet.Tables[0];
            cmbSubBuildAttribute.DisplayMember = dataSet.Tables[0].Columns["SBAContent"].ToString();
            cmbSubBuildAttribute.ValueMember = dataSet.Tables[0].Columns["SBAID"].ToString();

        }
        private void CmbBuildDcriterionNameDataBinding(int dtid)
        {
            dataSet = new DataSet();
            bllBuildDesignDcriterionSubType = new BLL.T_BuildDesignDcriterionSubTypes();
            dataSet = bllBuildDesignDcriterionSubType.GetList("DTID=" + "'" + dtid + "'");
            cmbBuildDcriterionName.DataSource = dataSet.Tables[0];
            cmbBuildDcriterionName.DisplayMember = dataSet.Tables[0].Columns["DSTName"].ToString();
            cmbBuildDcriterionName.ValueMember = dataSet.Tables[0].Columns["DSTID"].ToString();
        }
        private void cmbResultDcriterionDataBinding(int dtid)
        {
            dataSet = new DataSet();
            bllBuildDesignDcriterionSubType = new BLL.T_BuildDesignDcriterionSubTypes();
            dataSet = bllBuildDesignDcriterionSubType.GetList("DTID=" + "'" + dtid + "'");
            cmbResultDcriterion.DataSource = dataSet.Tables[0];
            cmbResultDcriterion.DisplayMember = dataSet.Tables[0].Columns["DSTName"].ToString();
            cmbResultDcriterion.ValueMember = dataSet.Tables[0].Columns["DSTID"].ToString();
        }
        private void cmbResulitContentDataBinding(int dstid)
        {
            dataSet = new DataSet();
            bllBuildDesignDcriterionContent = new BLL.T_BuildDesignDcriterionContents();
            dataSet = bllBuildDesignDcriterionContent.GetList("DSTID=" + "'" + dstid + "'");
            cmbResulitContent.DataSource = dataSet.Tables[0];
            cmbResulitContent.DisplayMember = dataSet.Tables[0].Columns["DcriterionContent"].ToString();
            cmbResulitContent.ValueMember = dataSet.Tables[0].Columns["DCID"].ToString();
            foreach (DataRow dr in dataSet.Tables[0].Rows)
            {
                txtRule.Text = dr["DcriterionRules"].ToString();
            }
        }
        private void cmbSubBuildAttribute_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                sbaid = Convert.ToInt32(cmbSubBuildAttribute.SelectedValue);
                cmbSubAttribute.DataSource = null;
                SubAttributeDataBinding(sbaid);
            }
            catch (Exception ex)
            {
                System.Data.DataRowView drv = (DataRowView)cmbSubBuildAttribute.SelectedValue;
                sbaid = Convert.ToInt32(drv.Row["SBAID"]);
            }
        }
        private void CmbBuildDcriterionContentDataBinding(int dstid)
        {
            dataSet = new DataSet();
            bllBuildDesignDcriterionContent = new BLL.T_BuildDesignDcriterionContents();
            dataSet = bllBuildDesignDcriterionContent.GetList("DSTID=" + "'" + dstid + "'");
            cmbBuildDcriterionContent.DataSource = dataSet.Tables[0];
            cmbBuildDcriterionContent.DisplayMember = dataSet.Tables[0].Columns["DcriterionContent"].ToString();
            cmbBuildDcriterionContent.ValueMember = dataSet.Tables[0].Columns["DCID"].ToString();
        }
        private void SubAttributeDataBinding(int sbaid)
        {
            dataSet = new DataSet();
            bllSubAttribute = new BLL.T_SubAttributes();
            dataSet = bllSubAttribute.GetList("SBAID=" + "'" + sbaid + "'");
            cmbSubAttribute.DataSource = dataSet.Tables[0];
            cmbSubAttribute.DisplayMember = dataSet.Tables[0].Columns["SAContent"].ToString();
            cmbSubAttribute.ValueMember = dataSet.Tables[0].Columns["SAID"].ToString();
        }
        private bool CheckIsAdd(List<Model.T_SubBuildDcriterionDesignAttributes> listAttributes, List<Model.T_SubBuildDcriterionConditions> listConditions, List<Model.T_SubBuildDcriterionContents> listContents)
        {
            bllSubBuildDcriterionDesignAttribute = new BLL.T_SubBuildDcriterionDesignAttributes();
            bllSubBuildDcriterionCondition = new BLL.T_SubBuildDcriterionConditions();
            bllSubBuildDcriterionDesignAttribute = new BLL.T_SubBuildDcriterionDesignAttributes();
            bllSubBuildDcriterionContent = new BLL.T_SubBuildDcriterionContents();
            bllSubBuildDcriterionList = new BLL.T_SubBuildDcriterionList();
            dataSet = new DataSet();
            dataSet = bllSubBuildDcriterionList.GetList("SBTID=" + "'" + this.sbtid + "'");
            if (dataSet.Tables[0].Rows.Count != 0)
            {
                foreach (DataRow dr in dataSet.Tables[0].Rows)
                {

                    sbdcid = dr["SBDCID"].ToString();
                    // List<string> listSbdcid = new List<string>();
                    if (listAttributes.Count != 0 && listContents.Count != 0 && listConditions.Count != 0)
                    {
                        DataSet condtionDataSet = new DataSet();
                        DataSet contentDataSet = new DataSet();
                        DataSet attributeDataSet = new DataSet();
                        attributeDataSet = bllSubBuildDcriterionDesignAttribute.GetList("SBDCID=" + "'" + sbdcid + "'");
                        contentDataSet = bllSubBuildDcriterionContent.GetList("SBDCID=" + "'" + sbdcid + "'");
                        condtionDataSet = bllSubBuildDcriterionCondition.GetList("SBDCID=" + "'" + sbdcid + "'");
                        foreach (Model.T_SubBuildDcriterionDesignAttributes sa in listSubBuildDcriterionDesignAttribute)
                        {
                            foreach (DataRow dw in attributeDataSet.Tables[0].Rows)
                            {
                                if (Convert.ToInt32(dw["SAID"]) == sa.SAID)
                                {
                                    s1 = dw["SBDCID"].ToString();
                                    break;
                                }
                                else
                                {
                                    s1 = "S1不存在";
                                }
                            }

                        }
                        if (condtionDataSet.Tables[0].Rows.Count != 0)
                        {
                            foreach (Model.T_SubBuildDcriterionConditions sc in listSubBuildDcriterionCondition)
                            {
                                foreach (DataRow da in condtionDataSet.Tables[0].Rows)
                                {
                                    if (sc.DCID == Convert.ToInt32(da["DCID"]))
                                    {
                                        s2 = (da["SBDCID"]).ToString();
                                        break;
                                    }
                                    else
                                    {
                                        s2 = "S2不存在";
                                    }
                                }
                            }
                        }
                        else
                        {
                            s2 = "虚拟S2数据";
                        }
                        if (contentDataSet.Tables[0].Rows.Count != 0)
                        {
                            foreach (Model.T_SubBuildDcriterionContents dc in listResult)
                            {
                                foreach (DataRow dd in contentDataSet.Tables[0].Rows)
                                {
                                    if (dc.DCID == Convert.ToInt32(dd["DCID"]))
                                    {
                                        s3 = dd["SBDCID"].ToString();
                                        break;
                                    }
                                    else
                                    {
                                        s3 = "S3不存在";
                                    }
                                }
                            }
                        }
                        else
                        {
                            s3 = "虚拟S3数据";
                        }
                        if (condtionDataSet.Tables[0].Rows.Count != 0)
                        {
                            if (s1 == s2 && s2 == s3)
                            {
                                isAdd = true;
                            }
                            else
                            {
                                isAdd = false;
                            }
                        }
                        else
                        {
                            if (s1 == s3)
                            {
                                isAdd = true;
                            }
                            else
                            {
                                isAdd = false;
                            }
                        }
                    }
                    else
                    {
                        if (listAttributes.Count != 0 && listContents.Count != 0)
                        {
                            DataSet contentDataSet = new DataSet();
                            DataSet attributeDataSet = new DataSet();
                            attributeDataSet = bllSubBuildDcriterionDesignAttribute.GetList("SBDCID=" + "'" + sbdcid + "'");
                            contentDataSet = bllSubBuildDcriterionContent.GetList("SBDCID=" + "'" + sbdcid + "'");
                            foreach (Model.T_SubBuildDcriterionDesignAttributes sa in listSubBuildDcriterionDesignAttribute)
                            {
                                foreach (DataRow dw in attributeDataSet.Tables[0].Rows)
                                {
                                    if (Convert.ToInt32(dw["SAID"]) == sa.SAID)
                                    {
                                        s1 = dw["SBDCID"].ToString();
                                        break;
                                    }
                                    else
                                    {
                                        s1 = "S1不存在";
                                    }
                                }

                            }
                            foreach (Model.T_SubBuildDcriterionContents dc in listResult)
                            {
                                foreach (DataRow dd in contentDataSet.Tables[0].Rows)
                                {
                                    if (dc.DCID == Convert.ToInt32(dd["DCID"]))
                                    {
                                        s3 = dd["SBDCID"].ToString();
                                        break;
                                    }
                                    else
                                    {
                                        s3 = "S3不存在";
                                    }
                                }
                            }
                        }
                        if (s1 == s3)
                        {
                            isAdd = true;
                        }
                        else
                        {
                            isAdd = false;
                        }
                    }
                    if (isAdd == true)
                    {
                        break;
                    }
                }
                return isAdd;
            }
            else
            {
                return isAdd = false;
            }
        }
        private void btnOk_Click_1(object sender, EventArgs e)
        {
            if (listSubBuildDcriterionDesignAttribute.Count != 0)
            {
                if (listResult.Count != 0)
                {
                    if (listSubBuildDcriterionCondition.Count != 0)
                    {
                        foreach (Model.T_SubBuildDcriterionConditions sc in listSubBuildDcriterionCondition)
                        {
                            foreach (Model.T_SubBuildDcriterionContents sd in listResult)
                            {
                                if (sc.SBDCID == sd.SBDCID && sc.DCID == sd.DCID)
                                {
                                    isSame = true;
                                    break;
                                }
                                else
                                {
                                    isSame = false;
                                }
                            }
                        }
                    }
                    if (isSame == false)
                    {
                        if (CheckIsAdd(listSubBuildDcriterionDesignAttribute, listSubBuildDcriterionCondition, listResult) == false)
                        {
                            Guid sbdcid = Guid.NewGuid();
                            bllSubBuildDcriterionList = new BLL.T_SubBuildDcriterionList();
                            bllSubBuildDcriterionContent = new BLL.T_SubBuildDcriterionContents();
                            bllSubBuildDcriterionCondition = new BLL.T_SubBuildDcriterionConditions();
                            bllSubBuildDcriterionDesignAttribute = new BLL.T_SubBuildDcriterionDesignAttributes();
                            modelSubBuildDcriterionList.SBDCID = sbdcid.ToString();
                            modelSubBuildDcriterionList.SBTID = this.sbtid;
                            modelSubBuildDcriterionList.DSTID = Convert.ToInt32(cmbResulitContent.SelectedValue);
                            try
                            {
                                bllSubBuildDcriterionList.Add(modelSubBuildDcriterionList);
                                if (listSubBuildDcriterionCondition.Count != 0)
                                {
                                    foreach (Model.T_SubBuildDcriterionDesignAttributes da in listSubBuildDcriterionDesignAttribute)
                                    {
                                        da.SBDCID = sbdcid.ToString();
                                        bllSubBuildDcriterionDesignAttribute.Add(da);
                                    }
                                    foreach (Model.T_SubBuildDcriterionConditions dc in listSubBuildDcriterionCondition)
                                    {
                                        dc.SBDCID = sbdcid.ToString();
                                        bllSubBuildDcriterionCondition.Add(dc);
                                    }
                                    foreach (Model.T_SubBuildDcriterionContents da in listResult)
                                    {
                                        da.SBDCID = sbdcid.ToString();
                                        bllSubBuildDcriterionContent.Add(da);

                                    }
                                    listResult.Clear();
                                    listSubBuildDcriterionCondition.Clear();
                                    listSubBuildDcriterionDesignAttribute.Clear();
                                    MessageBox.Show("添加成功！");
                                }
                                else
                                {
                                    foreach (Model.T_SubBuildDcriterionDesignAttributes da in listSubBuildDcriterionDesignAttribute)
                                    {
                                        da.SBDCID = sbdcid.ToString();
                                        bllSubBuildDcriterionDesignAttribute.Add(da);
                                    }
                                    foreach (Model.T_SubBuildDcriterionContents da in listResult)
                                    {
                                        da.SBDCID = sbdcid.ToString();
                                        bllSubBuildDcriterionContent.Add(da);
                                        listResult.Clear();
                                        listSubBuildDcriterionCondition.Clear();
                                        listSubBuildDcriterionDesignAttribute.Clear();
                                        MessageBox.Show("添加成功！");
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                //  MessageBox.Show(ex.Message.ToString());
                            }
                        }
                        else
                        {
                            listResult.Clear();
                            listSubBuildDcriterionCondition.Clear();
                            listSubBuildDcriterionDesignAttribute.Clear();
                            MessageBox.Show("该记录已经存在，请勿重复添加！");
                        }
                    }
                    else
                    {
                        listResult.Clear();
                        listSubBuildDcriterionCondition.Clear();
                        listSubBuildDcriterionDesignAttribute.Clear();
                        MessageBox.Show("所选规范条件与所需规范结果一样，请重新选择！");
                    }
                }
                else
                {
                    MessageBox.Show("规范结果项不能为空！");
                }
            }
            else
            {
                MessageBox.Show("请选择或填入信息！");
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (listSubBuildDcriterionDesignAttribute.Count >= 1)
            {
                bool isSelect = false;
                for (int i = 0; i < listSubBuildDcriterionDesignAttribute.Count; i++)
                {
                    if (Convert.ToInt32(cmbSubAttribute.SelectedValue) != listSubBuildDcriterionDesignAttribute[i].SAID)
                    {
                        isSelect = false;
                    }
                    else
                    {
                        isSelect = true;
                        break;
                    }
                }
                if (isSelect == false)
                {
                    modelSubBuildDcriterionDesignAttribute = new Model.T_SubBuildDcriterionDesignAttributes();
                    modelSubBuildDcriterionDesignAttribute.SAID = Convert.ToInt32(cmbSubAttribute.SelectedValue);
                    listSubBuildDcriterionDesignAttribute.Add(modelSubBuildDcriterionDesignAttribute);
                    Model.T_SubBuildAttributes modelSubBuildAttribute = new Model.T_SubBuildAttributes();
                    Model.T_SubAttributes modelSubAttribute = new Model.T_SubAttributes();
                    Model.AddSelectAttributes modelAddSelectAttribute = new AddSelectAttributes();
                    BDCS.Common.AddResult.selectAttributeText = string.Empty;
                    modelSubBuildDcriterionDesignAttribute.SAID = Convert.ToInt32(cmbSubAttribute.SelectedValue);
                    DataRowView drv1 = (DataRowView)cmbSubBuildAttribute.SelectedItem;
                    DataRowView drv = (DataRowView)cmbSubAttribute.SelectedItem;
                    string selectAttribute = drv.Row["SAContent"].ToString();
                    string selectSubAttribute = drv1.Row["SBAContent"].ToString();
                    modelSubAttribute.SAContent = selectAttribute;
                    modelSubBuildAttribute.SBAContent = selectSubAttribute;
                    modelAddSelectAttribute.SelectSubAttribute = selectSubAttribute;
                    modelAddSelectAttribute.SelectAttribute = selectAttribute;
                    //listSubBuildAttribute.Add(modelSubBuildAttribute);
                    // listSubAttribute.Add(modelSubAttribute);
                    listAddSelectAttribute.Add(modelAddSelectAttribute);
                    // isAdd = false;
                    BDCS.Common.AddResult.selectAttributeText += selectSubAttribute + "," + selectAttribute + ";";
                    selectAttribute = string.Empty;
                    selectSubAttribute = string.Empty;
                    label6.Text += BDCS.Common.AddResult.selectAttributeText;
                }
                else
                {
                    DataRowView drv1 = (DataRowView)cmbSubBuildAttribute.SelectedItem;
                    DataRowView drv = (DataRowView)cmbSubAttribute.SelectedItem;
                    string selectAttribute = drv.Row["SAContent"].ToString();
                    string selectSubAttribute = drv1.Row["SBAContent"].ToString();
                    MessageBox.Show("所选参数:" + "建筑属性名=" + "'" + selectSubAttribute + "'" + "," + "建筑属性值=" + "'" + selectAttribute + "'" + "重复，请重新添加！");
                }
            }
            else
            {
                modelSubBuildDcriterionDesignAttribute = new Model.T_SubBuildDcriterionDesignAttributes();
                Model.T_SubBuildAttributes modelSubBuildAttribute = new Model.T_SubBuildAttributes();
                Model.T_SubAttributes modelSubAttribute = new Model.T_SubAttributes();
                Model.AddSelectAttributes modelAddSelectAttribute = new AddSelectAttributes();
                BDCS.Common.AddResult.selectAttributeText = string.Empty;
                modelSubBuildDcriterionDesignAttribute.SAID = Convert.ToInt32(cmbSubAttribute.SelectedValue);
                listSubBuildDcriterionDesignAttribute.Add(modelSubBuildDcriterionDesignAttribute);
                // isAdd = false;
                DataRowView drv1 = (DataRowView)cmbSubBuildAttribute.SelectedItem;
                DataRowView drv = (DataRowView)cmbSubAttribute.SelectedItem;
                string selectAttribute = drv.Row["SAContent"].ToString();
                string selectSubAttribute = drv1.Row["SBAContent"].ToString();
                modelAddSelectAttribute.SelectAttribute = selectAttribute;
                modelAddSelectAttribute.SelectSubAttribute = selectSubAttribute;
                listAddSelectAttribute.Add(modelAddSelectAttribute);
                BDCS.Common.AddResult.selectAttributeText += selectSubAttribute + "," + selectAttribute + ";";
                selectAttribute = string.Empty;
                selectSubAttribute = string.Empty;
                label6.Text += BDCS.Common.AddResult.selectAttributeText;
                //label6.ForeColor = Color.DarkBlue;
            }

        }

        private void button4_Click(object sender, EventArgs e)
        {
            modelSubBuildDcriterionCondition = new Model.T_SubBuildDcriterionConditions();
            Model.AddDcriterions modelAddDcriterion = new AddDcriterions();
            bool isSelect = false;
            if (listSubBuildDcriterionCondition.Count >= 1)
            {
                for (int i = 0; i < listSubBuildDcriterionCondition.Count; i++)
                {
                    if (listSubBuildDcriterionCondition[i].DCID != Convert.ToInt32(cmbBuildDcriterionContent.SelectedValue))
                    {
                        isSelect = false;
                    }
                    else
                    {
                        isSelect = true;
                        break;
                    }
                }
                if (isSelect == false)
                {
                    modelSubBuildDcriterionCondition.DCID = Convert.ToInt32(cmbBuildDcriterionContent.SelectedValue);
                    listSubBuildDcriterionCondition.Add(modelSubBuildDcriterionCondition);
                    //isAdd = false;
                    BDCS.Common.AddResult.selectDcriterionText = string.Empty;
                    DataRowView drv = (DataRowView)cmbBuildDcriterionName.SelectedItem;
                    DataRowView drv1 = (DataRowView)cmbBuildDcriterionContent.SelectedItem;
                    string selectDcriterion = drv.Row["DSTName"].ToString();
                    string selectContent = drv1.Row["DcriterionContent"].ToString();
                    modelAddDcriterion.DSTName = selectDcriterion;
                    modelAddDcriterion.DcriterionContent = selectContent;
                    listAddDcriterion.Add(modelAddDcriterion);

                    BDCS.Common.AddResult.selectDcriterionText += selectDcriterion + "," + selectContent + ";";
                    selectDcriterion = string.Empty;
                    selectContent = string.Empty;
                    label9.Text += BDCS.Common.AddResult.selectDcriterionText;
                }
                else
                {
                    DataRowView drv = (DataRowView)cmbBuildDcriterionName.SelectedItem;
                    DataRowView drv1 = (DataRowView)cmbBuildDcriterionContent.SelectedItem;
                    string selectDcriterion = drv.Row["DSTName"].ToString();
                    string selectContent = drv1.Row["DcriterionContent"].ToString();
                    MessageBox.Show("所选规范:" + "规范名称=" + "'" + selectDcriterion + "'" + "," + "建筑属性值=" + "'" + selectContent + "'" + "重复，请重新添加！");
                }
            }
            else
            {
                modelSubBuildDcriterionCondition.DCID = Convert.ToInt32(cmbBuildDcriterionContent.SelectedValue);
                listSubBuildDcriterionCondition.Add(modelSubBuildDcriterionCondition);
                // isAdd = false;
                DataRowView drv = (DataRowView)cmbBuildDcriterionName.SelectedItem;
                DataRowView drv1 = (DataRowView)cmbBuildDcriterionContent.SelectedItem;
                string selectDcriterion = drv.Row["DSTName"].ToString();
                string selectContent = drv1.Row["DcriterionContent"].ToString();
                modelAddDcriterion.DSTName = selectDcriterion;
                modelAddDcriterion.DcriterionContent = selectContent;
                listAddDcriterion.Add(modelAddDcriterion);
                BDCS.Common.AddResult.selectDcriterionText += selectDcriterion + "," + selectContent + ";";
                selectDcriterion = string.Empty;
                selectContent = string.Empty;
                label9.Text += BDCS.Common.AddResult.selectDcriterionText;
            }

            // label9.ForeColor = Color.DarkBlue;

        }
        private void button3_Click(object sender, EventArgs e)
        {
            if (listAddSelectAttribute.Count == 0)
            {
                label6.Text = "所添加的类别参数包括：";
                MessageBox.Show("没有添加任何属性信息，不需要取消操作！");
            }
            else
            {
                DataRowView drv1 = (DataRowView)cmbSubBuildAttribute.SelectedItem;
                DataRowView drv = (DataRowView)cmbSubAttribute.SelectedItem;
                string selectAttribute = drv.Row["SAContent"].ToString();
                string selectSubAttribute = drv1.Row["SBAContent"].ToString();
                int index = 0;
                int indexTwo = 0;
                if (listAddSelectAttribute.Count != 0)
                {
                    for (int i = 0; i < listAddSelectAttribute.Count; i++)
                    {
                        if (listAddSelectAttribute[i].SelectAttribute == selectAttribute && listAddSelectAttribute[i].SelectSubAttribute == selectSubAttribute)
                        {
                            index = i;
                            listAddSelectAttribute.RemoveAt(index);
                        }
                    }
                    for (int i = 0; i < listSubBuildDcriterionDesignAttribute.Count; i++)
                    {
                        if (listSubBuildDcriterionDesignAttribute[i].SAID == Convert.ToInt32(cmbSubAttribute.SelectedValue))
                        {
                            indexTwo = i;
                            listSubBuildDcriterionDesignAttribute.RemoveAt(indexTwo);
                        }
                    }
                    BDCS.Common.AddResult.selectAttributeText = string.Empty;
                    foreach (Model.AddSelectAttributes aa in listAddSelectAttribute)
                    {
                        BDCS.Common.AddResult.selectAttributeText += aa.SelectSubAttribute + "," + aa.SelectAttribute + ";";
                    }
                    label6.Text = string.Empty;
                    label6.Text += "所添加的类别参数包括：" + BDCS.Common.AddResult.selectAttributeText;
                    // listSubBuildDcriterionDesignAttribute.Remove(listSubBuildDcriterionDesignAttribute[listSubBuildDcriterionDesignAttribute.Count - 1]);
                }
                else
                {
                    listSubBuildDcriterionDesignAttribute.Clear();
                    listAddSelectAttribute.Clear();
                    label6.Text += "所添加的类别参数包括：";
                    MessageBox.Show("没有添加任何属性参数信息！");
                }
            }
        }
        private void button5_Click(object sender, EventArgs e)
        {
            if (listAddDcriterion.Count == 0)
            {
                label9.Text = "所添加的规范参数包括";
                MessageBox.Show("没有添加任何规范信息，不需要取消操作！");
            }
            else
            {
                DataRowView drv = (DataRowView)cmbBuildDcriterionName.SelectedItem;
                DataRowView drv1 = (DataRowView)cmbBuildDcriterionContent.SelectedItem;
                string selectDcriterion = drv.Row["DSTName"].ToString();
                string selectContent = drv1.Row["DcriterionContent"].ToString();
                int index = 0;
                int indexTwo = 0;
                if (listAddDcriterion.Count != 0)
                {

                    for (int i = 0; i < listAddDcriterion.Count; i++)
                    {
                        if (listAddDcriterion[i].DSTName == selectDcriterion && listAddDcriterion[i].DcriterionContent == selectContent)
                        {
                            index = i;
                            listAddDcriterion.RemoveAt(index);
                        }
                    }
                    for (int i = 0; i < listSubBuildDcriterionCondition.Count; i++)
                    {
                        if (listSubBuildDcriterionCondition[i].DCID == Convert.ToInt32(cmbBuildDcriterionContent.SelectedValue))
                        {
                            indexTwo = i;
                            listSubBuildDcriterionCondition.RemoveAt(indexTwo);
                        }
                    }
                    BDCS.Common.AddResult.selectDcriterionText = string.Empty;
                    foreach (Model.AddDcriterions a in listAddDcriterion)
                    {
                        BDCS.Common.AddResult.selectDcriterionText += a.DSTName + "," + a.DcriterionContent + ";";
                    }
                    label9.Text = string.Empty;
                    label9.Text += "所添加的类别参数包括：" + BDCS.Common.AddResult.selectDcriterionText;
                }
                else
                {
                    listAddDcriterion.Clear();
                    listSubBuildDcriterionCondition.Clear();
                    label9.Text = "所添加的规范参数包括";
                    MessageBox.Show("没有添加任何规范参数信息！");
                }
            }
        }

        private void cmbResultDcriterion_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                dstidTwo = Convert.ToInt32(cmbResultDcriterion.SelectedValue);
                cmbResulitContentDataBinding(dstidTwo);
            }
            catch (Exception ex)
            {
                System.Data.DataRowView drv = (DataRowView)cmbResultDcriterion.SelectedValue;
                dstidTwo = Convert.ToInt32(drv.Row["DSTID"]);
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            modelSubBuildDcriterionContent = new Model.T_SubBuildDcriterionContents();
            bool isSelect = false;
            if (listResult.Count >= 1)
            {
                for (int i = 0; i < listResult.Count; i++)
                {
                    if (listResult[i].DCID != Convert.ToInt32(cmbResulitContent.SelectedValue))
                    {
                        isSelect = false;
                    }
                    else
                    {
                        isSelect = true;
                        break;
                    }
                }
                if (isSelect == false)
                {
                    isAdd = true;
                    modelSubBuildDcriterionContent = new Model.T_SubBuildDcriterionContents();
                    modelSubBuildDcriterionContent.DCID = Convert.ToInt32(cmbResulitContent.SelectedValue);
                    listResult.Add(modelSubBuildDcriterionContent);
                    DataRowView drv = (DataRowView)cmbResultDcriterion.SelectedItem;
                    DataRowView drv1 = (DataRowView)cmbResulitContent.SelectedItem;
                    string selectDcriterion = drv.Row["DSTName"].ToString();
                    string selectContent = drv1.Row["DcriterionContent"].ToString();
                    Model.AddConterns modelAddContent = new AddConterns();
                    modelAddContent.DSTName = selectDcriterion;
                    modelAddContent.DcriterionContent = selectContent;
                    listAddContent.Add(modelAddContent);
                    BDCS.Common.AddResult.selectResultText = string.Empty;
                    BDCS.Common.AddResult.selectResultText = selectDcriterion + "," + selectContent + ";";
                    label10.Text += BDCS.Common.AddResult.selectResultText;
                }
                else
                {
                    DataRowView drv = (DataRowView)cmbResultDcriterion.SelectedItem;
                    DataRowView drv1 = (DataRowView)cmbResulitContent.SelectedItem;
                    string selectDcriterion = drv.Row["DSTName"].ToString();
                    string selectContent = drv1.Row["DcriterionContent"].ToString();
                    MessageBox.Show("所选规范:" + "规范名称=" + "'" + selectDcriterion + "'" + "," + "建筑属性值=" + "'" + selectContent + "'" + "重复，请重新添加！");
                }
            }
            else
            {
                //   isAdd = true;
                modelSubBuildDcriterionContent = new Model.T_SubBuildDcriterionContents();
                modelSubBuildDcriterionContent.DCID = Convert.ToInt32(cmbResulitContent.SelectedValue);
                listResult.Add(modelSubBuildDcriterionContent);
                DataRowView drv = (DataRowView)cmbResultDcriterion.SelectedItem;
                DataRowView drv1 = (DataRowView)cmbResulitContent.SelectedItem;
                string selectDcriterion = drv.Row["DSTName"].ToString();
                string selectContent = drv1.Row["DcriterionContent"].ToString();
                Model.AddConterns modelAddContent = new AddConterns();
                modelAddContent.DSTName = selectDcriterion;
                modelAddContent.DcriterionContent = selectContent;
                listAddContent.Add(modelAddContent);
                BDCS.Common.AddResult.selectResultText = string.Empty;
                BDCS.Common.AddResult.selectResultText = selectDcriterion + "," + selectContent + ";";
                label10.Text += BDCS.Common.AddResult.selectResultText;
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (listResult.Count == 0)
            {
                label10.Text = "该类别建筑对于的具体规范为：";
                MessageBox.Show("没有添加任何规范信息，不需要取消操作！");
            }
            else
            {
                DataRowView drv = (DataRowView)cmbResultDcriterion.SelectedItem;
                DataRowView drv1 = (DataRowView)cmbResulitContent.SelectedItem;
                string selectDcriterion = drv.Row["DSTName"].ToString();
                string selectContent = drv1.Row["DcriterionContent"].ToString();
                int index;
                int indexTwo;
                if (listResult.Count != 0)
                {
                    for (int i = 0; i < listAddContent.Count; i++)
                    {
                        if (listAddContent[i].DSTName == selectDcriterion && listAddContent[i].DcriterionContent == selectContent)
                        {
                            index = i;
                            listAddContent.RemoveAt(index);
                        }
                    }
                    for (int i = 0; i < listResult.Count; i++)
                    {
                        if (listResult[i].DCID == Convert.ToInt32(cmbResulitContent.SelectedValue))
                        {
                            indexTwo = i;
                            listResult.RemoveAt(indexTwo);
                        }
                    }
                    BDCS.Common.AddResult.selectResultText = string.Empty;
                    foreach (Model.AddConterns a in listAddContent)
                    {
                        BDCS.Common.AddResult.selectResultText += a.DSTName + "," + a.DcriterionContent + ";";
                    }
                    label10.Text = string.Empty;
                    label10.Text += "该类别建筑对于的具体规范为："+ BDCS.Common.AddResult.selectResultText;
                }
                else
                {
                    listAddContent.Clear();
                    listResult.Clear();
                    label10.Text = "该类别建筑对于的具体规范为：";
                    MessageBox.Show("没有添加任何规范参数信息！");
                }
            }
        }

        private void cmbBuildDcriterionContent_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                dstid = Convert.ToInt32(cmbBuildDcriterionContent.SelectedValue);
            }
            catch (Exception ex)
            {
                DataRowView dr = (DataRowView)cmbBuildDcriterionContent.SelectedValue;
                dstid = Convert.ToInt32(dr.Row["DSTID"]);
            }
        }

        private void cmbBuildDcriterionName_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                dstid = Convert.ToInt32(cmbBuildDcriterionName.SelectedValue);
                CmbBuildDcriterionContentDataBinding(dstid);
            }
            catch (Exception ex)
            {
                System.Data.DataRowView drv = (DataRowView)cmbBuildDcriterionName.SelectedValue;
                dstid = Convert.ToInt32(drv.Row["DSTID"]);
            }
        }

        private void cmbResulitContent_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                dstidTwo = Convert.ToInt32(cmbResultDcriterion.SelectedValue);
                cmbResulitContentDataBinding(dstidTwo);
            }
            catch (Exception ex)
            {
                DataRowView drv = (DataRowView)cmbResultDcriterion.SelectedValue;
                dstidTwo = Convert.ToInt32(drv.Row["DSTID"]);
            }
        }
    }
}
